import agentHttp from '@/utils/agentHttp.js'//引用JS
import dialogForm from './edit'
import pagination from '@/views/pagination'  //分页组件
import {debounce,setEndDateTime} from '@/utils/index.js'
export default {
  name: 'vehicleFollow',
  components: {
    dialogForm,pagination
  },
  created() {
    this.seachData();
  },
  data() {
    return {
      //搜索字段
      searchForm: {
        startDate:"",
        endDate:"",
        status:"",
        carOrderStatus:""
      },
      //表格字段
      tableData: [{
      }],
      //弹窗状态数据
      dialogSendData:{
        isAdd:"",
        dialogFormVisible:"",
        carOrderId:""
      },
      statusMap:'',
      carOrderStatusMap:'',
      startDateOpt: {
             disabledDate(time) {
                return time.getTime() > Date.now() 
             }
          },
      endDateOpt:{
        disabledDate:(time)=>{
                return  time.getTime()< new Date(this.searchForm.startDate).getTime();
             }
      },
      resetFormStatus:false
    }
  },

  methods: {
    /*搜索按钮方法*/
    //搜索
    seachData(){
      if(!this.resetFormStatus){
        var params=this.searchForm||{};
        params.page=this.tableData.page||1;
        params.rows=this.tableData.rows||10;
        params.endDate = setEndDateTime(params.endDate);
        agentHttp.postJson('adminApi/admin/cash_deposit_info/list?page='+params.page+'&rows='+params.rows,params ).then((data)=>{
          if (data.success) {
            this.statusMap = data.data.statusMap;
            this.carOrderStatusMap = data.data.carOrderStatusMap; 
            this.tableData = data.data.tableData; 
          }              
        })
      }
    },
    //延迟搜索
    debounceSeach(){
      this.tableData.page=1;
      debounce(this.seachData(),1000);
    },
    //重置
    resetSearchForm(formName) {
      this.resetFormStatus=true;
      this.tableData.page=1;
      this.tableData.rows=10;
      this.$refs[formName].resetFields();
      this.$nextTick(_ =>{
        this.resetFormStatus=false;
        this.seachData();
      })
    },
    /*表格操作按钮*/
    //查看
    handleSee(index, row) {
      row?this.dialogSendData.carOrderId=row.carOrderId:this.dialogSendData.carOrderId="";
      this.dialogSendData.isAdd=false;
      this.dialogSendData.dialogFormVisible=true;

    },
    //新增、编辑
    handleEdit(index, row){
      row?this.dialogSendData.carOrderId=row.carOrderId:this.dialogSendData.carOrderId="";
      this.dialogSendData.isAdd=true;
      this.dialogSendData.dialogFormVisible=true;
    }   
  }
}